package com.mission.game.creategame;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.mission.game.R;

public class CreateTaskScreen extends Activity {

	private ArrayList<String> _taskList;
	
	private Button _pictureButton;
	private Button _gpsButton;
	private Button _textButton;
	private Button _barcodeButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.create_new_task);

		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			if (extras.containsKey("tasklist")) {
				_taskList = extras.getStringArrayList("tasklist");
			} else {//Shouldn't get here, can't have a stand-alone task.
				return;
			}
		}
		
		_pictureButton = (Button) findViewById(R.id.picture_task_button);
		_gpsButton = (Button) findViewById(R.id.gps_task_button);
		_textButton = (Button) findViewById(R.id.text_task_button);
		_barcodeButton = (Button) findViewById(R.id.barcode_task_button);
		
		_pictureButton.setOnClickListener(chooseTask);
		_gpsButton.setOnClickListener(chooseTask);
		_textButton.setOnClickListener(chooseTask);
		_barcodeButton.setOnClickListener(chooseTask);
	}

	OnClickListener chooseTask = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v == _pictureButton) {
				createSpecificTask(CreatePictureTask.class);
			} else if (v == _gpsButton) {
				createSpecificTask(CreateGPSTask.class);
			} else if (v == _textButton) {
				createSpecificTask(CreateTextTask.class);
			} else if (v == _barcodeButton) {
				createSpecificTask(CreateBarcodeTask.class);
			} else {
				return;
			}
		}
	};
	
	private void createSpecificTask(Class<?> taskClass) {
		Intent i = new Intent(getApplicationContext(),
				taskClass);
		i.putExtra("tasklist", _taskList);
		startActivityForResult(i, CreateMissionScreen.CREATE_TASK);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case CreateMissionScreen.CREATE_TASK:
			setResult(RESULT_OK, data);
			finish();
			break;
		default:
			break;
		}
	}
}
